package com.ruoyi.inspection.domain.receiveVo;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.constant.GlobalConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.inspection.constant.InspectionConstant;
import com.ruoyi.system.entity.LightningData;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 上报环境监测数据
 */
@Data
public class ReceiveEnvironMonitor implements Serializable {
    //// 唯一编码，36 位uuid，必填
    private String id;
    //设备编码 企业编码加三位流水号
    private String equipCode;
    /**
     * 采集时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date timeStamp;
    //风向 0:无 1:北 2:东北偏北 3:东北 4:东北偏东
    //5:东 6:东南偏东 7:东南 8:东南偏南 9:南 10:西南偏南 11:西南 12:西南偏西 13:西 14:西北偏西 15:西北 16:西北偏北
    private String windDirection;
    //风速 米/秒(m/s)
    private String windSpeed;
    /**
     * 停用结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date stopEndTime;
    //温度 摄氏度
    private String temperature;
    //风速 米/秒(m/s)
    private String humidity;


    public static ReceiveEnvironMonitor lightningDataToReceiveEnvironMonitor(LightningData lightningData) {
        ReceiveEnvironMonitor environMonitor = new ReceiveEnvironMonitor();
//        environMonitor.setId(enId(lightningData.getId()+lightningData.getMesureTime()) + "-002");
        environMonitor.setId(UUID.randomUUID().toString());
        environMonitor.setTimeStamp(new Date(Long.parseLong(lightningData.getMesureTime())));
        environMonitor.setWindDirection(calcWindDirection(lightningData.getWindspeed()));
        environMonitor.setEquipCode(GlobalConstants.COMPANY_CODE + "100");
        environMonitor.setTemperature(lightningData.getTemperature());
        environMonitor.setWindSpeed(lightningData.getWinddirect());
        environMonitor.setHumidity(lightningData.getHumidity());

        return environMonitor;
    }


    public static String enId(String id) {
        String a = "hjjcxxsbq-" + id + "-";
        String a1 = StrUtil.fillAfter(a, 'g', 32);
        return a1;
    }

    public static String calcWindDirection(String angle) {
        if (StringUtils.isEmpty(angle)) {
            return "0";
        }

        float angleFloat = Float.parseFloat(angle);
        if (angleFloat>=348.75 || angleFloat<11.25)  { return "1"; }
        if (angleFloat>=11.25 && angleFloat<33.75)  { return "2"; }
        if (angleFloat>=33.75 && angleFloat<56.25)  { return "3"; }
        if (angleFloat>=56.25 && angleFloat<78.75)  { return "4"; }
        if (angleFloat>=78.75 && angleFloat<101.25)  { return "5"; }
        if (angleFloat>=101.25 && angleFloat<123.75)  { return "6"; }
        if (angleFloat>=123.75 && angleFloat<146.25)  { return "7"; }
        if (angleFloat>=146.25 && angleFloat<168.75)  { return "8"; }
        if (angleFloat>=168.75 && angleFloat<191.25)  { return "9"; }
        if (angleFloat>=191.25 && angleFloat<213.75)  { return "10"; }
        if (angleFloat>=213.75 && angleFloat<236.25)  { return "11"; }
        if (angleFloat>=236.25 && angleFloat<258.75)  { return "12"; }
        if (angleFloat>=258.75 && angleFloat<281.25)  { return "13"; }
        if (angleFloat>=281.25 && angleFloat<303.75)  { return "14"; }
        if (angleFloat>=303.75 && angleFloat<326.25)  { return "15"; }
        if (angleFloat>=326.25 && angleFloat<348.75)  { return "16"; }

        return "0";
    }


}
